<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/pages/dynamic.jsp" %>
<html>
<head>
    <title></title>
    
    <style>
        .x-form-file-wrap {
            position: relative;
            height: 22px;
        }

        .x-form-file-wrap .x-form-file {
            position: absolute;
            right: 0;
            -moz-opacity: 0;
            filter: alpha(opacity : 0);
            opacity: 0;
            z-index: 2;
            height: 22px;
        }

        .x-form-file-wrap .x-form-file-btn {
            position: absolute;
            right: 0;
            z-index: 1;
        }

        .x-form-file-wrap .x-form-file-text {
            position: absolute;
            left: 0;
            z-index: 3;
            color: #777;
        }

        .backup h1{
            line-height: 100px;
            font-size: 30px;
            color:#f00;
            text-align: center;
        }
        .backup button{
            height:30px;
            width:50px;
            margin-left: 10px;
        }
        .backup input{
            height:30px;
        }
        #restoreDiv .x-btn-text{
            height:24px;
        }

        #backupForm,#restoreForm,.backup>div{
            margin: auto;
            width: 700px;
            margin-top: 50px;
        }
    </style>
    
    <script type="text/javascript">
		    Ext.onReady(function(){
		        var storeTheme=getCookie('theme');
		        if(storeTheme==null || storeTheme==''){
		            storeTheme='xtheme-newbluetheme';
		        }
		        Ext.util.CSS.swapStyleSheet("theme", __ctxPath+"/resources/ext3/resources/css/"+storeTheme+".css");  
		  });
        /* $("#backupForm").validate({
            rules: {
                backupPath:{
                    //required: true
                }
            },
            messages:{
                backupPath:{
                    //required:'备份路径不能为空！'
                }
            }
        });


        $("#restoreForm").validate({
            rules: {
                restoreFile:{
                    required: true
                }
            },
            messages:{
                restoreFile:{
                    required:'还原文件不能为空！'
                }
            }
        }); */

         function backup(){
//             suunCore.showMask();
        	Ext.Ajax.request({
                url : __ctxPath + "/backupBackup.do",
                success : function(q, s) {
                    var r = Ext.decode(q.responseText);
                    if (r.success == false) {
                        Ext.MessageBox.show({
                            title : "操作提示",
                            msg : r.msg,
                            buttons : Ext.MessageBox.OK,
                            icon : "ext-mb-error"
                        });                             
                    } else {
                        Ext.ux.Toast.msg("操作提示", "备份成功!");
                    }
                },
                failure : function(q, r) {
                	 Ext.ux.Toast.msg("操作提示", "备份失败，联系管理员!");
                }
            });
        }

/*        function downloadBak(){
          window.location = __ctxPath + "/bakupAndDowloadBackup.do",

//           suunCore.showMask();
          var backupPath = Ext.getCmp("backupForm").get(0).backupPath.value;
          Ext.Ajax.request({
              url : __ctxPath + "/backupBackup.do",
              data : {backupPath:backupPath},
              dataType : "json",
              success : function(msg){
                  
                  window.location =  __ctxPath + "/downloadBackup.do?filePath=";,
//                   suunCore.hideMask();
              },
              failure: function(){
//                   suunCore.hideMask();
              }
          });
        } */

         function restoreDB(){
           Ext.MessageBox.confirm('系统提示',
                        '此操作有风险，请谨慎操作！！！'+
                    '<div style="color:#f00;line-height: 20px;">' +
                        '1、还原数据库将会覆盖现在的数据，现有数据库中数据将丢失！<br/>'+
                        '2、还原时间较长，请耐心等待！<br/>' +
                        '是否还原数据库?'+
                    '</div>'
                    ,function(btn){
                    if(btn=='yes'){
//                         suunCore.showMask();
                        Ext.Ajax.request({
                            url:__ctxPath + "/restoreBackup.do",
                            form: Ext.getCmp("restoreForm"),
                            isUpload:true,
                            success:function(response){
                                var resp = response.responseText;
                                var info=eval("(" + resp + ")");
                                Ext.MessageBox.show({
                                    title : "系统提示",
                                    width: 300,
                                    msg : info.msg,
                                    icon : Ext.MessageBox.WARNING ,
                                    buttons : Ext.Msg.OK
                                });
//                                 suunCore.hideMask();
                            },
                            failure:function(){
//                                 suunCore.hideMask();
                            }
                        });
                    }
                });
        } 

            Ext.onReady(function(){
            new Ext.ux.form.FileUploadField({
                id: 'restoreId',
                emptyText: '选择还原的文件！',
                renderTo :'restoreDiv',
//                fieldLabel: '导入',
                name:'file',
                width : 264,
                buttonText: '选择文件',
                listeners:{
                    'fileselected': function(fb,filename){
                        var fileSize = document.getElementById('restoreId-file').files[0].size;
                        var fileSizeM = fileSize/1024/1024;
                        if(fileSizeM>100){
                            Ext.MessageBox.show({
                                title : '系统提示',
                                msg : '上传附件过大！最大支持文件大小100MB！',
                                buttons : Ext.MessageBox.OK,
                                icon : "ext-mb-error"
                            });
                            Ext.getCmp('restoreId-file').setValue('');
                            return;
                        }
                    }
                }
            })
        });


            //Demo
           function demoUpload(){
            	App.createUploadDialog({
                    callback : function(records){
                        var recordData=[];
                           Ext.each(records,function(record){
//                              recordData.push(record.data);
                        	    document.getElementById("demoUploadtext").value=record.data.fileName;
                        	    console.log(record.data.fileName);
                           });
                    },
                    multiSel : false
//                  file_cat : "production/sheetImg",
//                  callback : uploadUserPhoto,
//                  permitted_extensions : [ "jpg" ]
                }).show();
            }
    </script>
</head>
<body>
<div class="backup">
    <h1>此模块非超级管理员不能使用</h1><!-- ，系统所上传附件请在“数据中心”的“文件迁移”中进行备份与还原操作。 -->
    <center><font color="blue" style="margin-top: 150px;">说明：此功能仅支持系统数据库备份与还原</font></center>
    <hr style="width: 80%"/>
    <form id="backupForm" onsubmit="return false;">
        <div>
            <input type="text" name="backupPath" style="width:200px;" placeholder="请输入服务器备份文件的全路径"/>
            <button onclick="backup();" class="limsBtn">备份</button>
            <button onclick="downloadBak();" class="limsBtn">下载</button>
            <div style="color:#f00;margin-top: 5px;"> 备份路径例如：D:/backup/ptmsdb_20151209_103737_791.bak</div>
            <div style="color:#f00;margin-top: 5px;"> 如不指定路径，则默认备份路径为：${defaultBackupPath}</div>
        </div>
    </form>

    <form id="restoreForm" onsubmit="return false;">
        <div>
            <div id="restoreDiv" style="display: inline-block;"></div>
            <button onclick="restoreDB();" class="limsBtn" style="vertical-align: top;">还原</button><hr/>          
    <input id="demoUploadtext" style="width:200px;"/><button onclick="demoUpload();">上传例子</button>
        </div>
    </form>
    
</div>

</body>
</html>
